package com.dynamic.sync.toolkit.controller;

import lombok.Data;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ZonLen since on 2021/6/18 上午10:49
 */
@RestController
public class SplitController {

  @PostMapping("/split")
  public String split(@RequestBody SplitContent splitContent){
    final String content = splitContent.getContent();
    if (StringUtils.isEmpty(content)){
      return "";
    }
    final String separator = splitContent.getSeparator();
    if (StringUtils.isEmpty(separator)){
      return content;
    }
    return content.replaceAll(separator, "\n");
  }

  @Data
  public static class SplitContent{
    private String separator;

    private String content;
  }
}
